using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.SimpleTemp.Repositories.Sys;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class PX_ReportCardDetailService : BaseAppService<PX_ReportCardDetailDto, PX_ReportCardDetail , PX_ReportCardDetailRepository>
        {
        readonly ExcelHelp _excelHelp;
        public PX_ReportCardDetailService (PX_ReportCardDetailRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<PX_ReportCardDetail, PX_ReportCardDetailDto>
            GetLoadPageOffsetMode(PagingModel<PX_ReportCardDetailDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("ReportCardID","=") //
         .Add("DeptID","=") //
         .Add("UserID","=") //
         .Add("Success","=") //
         .Add("Remark","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  PX_ReportCardDetail() {
                Id = model.Id,
ReportCardID= model.ReportCardID,//
DeptID= model.DeptID,//
UserID= model.UserID,//
Success= model.Success,//
Remark= model.Remark,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<PX_ReportCardDetailDto>> GetList(PagingModel<PX_ReportCardDetailDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<PX_ReportCardDetailDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.ReportCardID,
ReportCardID_title ="",
model.DeptID,
DeptID_title ="",
model.UserID,
UserID_title ="",
model.Success,
Success_title ="",
model.Remark,
Remark_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
